package com.macro.mall.es.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.dto.EsIndexDto;
import com.macro.mall.es.service.EsIndexService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * es索引的服务
 */
@RestController
@RequestMapping("/index")
public class EsIndexController {
    @Resource
    private EsIndexService esIndexService;

    /**
     * 创建索引
     * @param esIndexDto
     * @return
     */
    @PostMapping("/creatProductIndex")
    public CommonResult createProductIndex(@Validated @RequestBody EsIndexDto esIndexDto){
        return esIndexService.createProductIndex(esIndexDto);
    }

    /**
     * 查询索引
     * @param indexName
     * @return
     */
    @PostMapping("/searchProduct/{indexName}")
    public CommonResult<Map<String,Object>> searchProductIndex(@PathVariable String indexName){
        return esIndexService.searchProductIndex(indexName);
    }

    /**
     * 校验索引
     * @param indexName
     * @return
     */
    @PostMapping("/searchIndexChecker/{indexName}")
    public CommonResult searchIndexChecker(@PathVariable String indexName){
        return esIndexService.searchIndexChecker(indexName);
    }

    /**
     * 修改索引
     * @param esIndexDto
     * @return
     */
    @PostMapping("/updateIndexProduct")
    public CommonResult updateIndexProduct(@Validated @RequestBody EsIndexDto esIndexDto){
        return esIndexService.updateIndexProduct(esIndexDto);
    }

    /**
     * 删除索引
     * @param indexName
     * @return
     */
    @PostMapping("/del/{indexName}")
    public CommonResult delProductIndex(@PathVariable String indexName){
        return esIndexService.delProductIndex(indexName);
    }
}
